//*************************************************************************************
// EGTB Generator Compression Routines
//*************************************************************************************

#pragma once

#include "EndGameDbCommon.h"
#include "..\Engine\PagingManager.h"
#include "..\Engine\CDbReader.h"

using namespace DbReader;

namespace EndGameDB
{
	// compression callback
	extern void (*OnCompressSubDbStartedPtr)(int wm, int wk, int bm, int bk, int wmrank, int bmrank);

	// compressed file headers
	extern EGTBMainHeader mainHeaderWDL;
	extern EGTBMainHeader mainHeaderDTM;

	extern EGTBSubDatabase* pWDLSubDbs;
	extern EGTBSubDatabase* pDTMSubDbs;

	// compression settings
	extern int32 g_nCompressionType;
	extern eCheckersType g_eCompressionCheckersType;
	extern uint32 g_nPageSize;
	extern uint32 g_nSubDbCount;
	extern uint32 g_nSubDbIndex;

	extern uint64 nWDLTotalBlockCount;
	extern uint64 nDTMTotalBlockCount;

	// paging managers - provides compression stream
	extern PagingManager* g_pWDLPageManager;
	extern PagingManager* g_pDTMPageManager;

	// pointer to the databases which are currently being computed.
	extern uint8 *currentdb_b, *currentdb_w; 
	extern uint8	*cur_dtm_b, *cur_dtm_w;

	// functions
	////////////////////////////////////////////////

	// Initializes Compression
	void InitCompress();

    // Finalizes the compression of one EGTB file
	void DoneDbCompression(FILE* wdlFile, FILE* dtmFile);

	// Sets the compression directory
	void SetDatabaseCprDirectory(const wchar_t* lpDir);

    // Add compression directory to the file
	void AttachCprDirectory(wchar_t* path, wchar_t *filename);
}
